home *** CD-ROM | disk | FTP | other *** search
- Path: server-b.cs.interbusiness.it!usenet
- From: albe@pinerolo.gvo.it (Alberto Velo)
- Newsgroups: comp.lang.c
- Subject: Re: Watcom: pad a string ?
- Date: Tue, 13 Feb 1996 19:35:44 -0100
- Organization: Centro Servizi Interbusiness
- Distribution: world
- Message-ID: <gYPIxQTC3YkO089yn@pinerolo.gvo.it>
- References: <ZCOExQTC3kJT089yn@pinerolo.gvo.it>
- <4f2ftf$rjb@sparcserver.lrz-muenchen.de>
- Reply-To: albe@pinerolo.gvo.it
- NNTP-Posting-Host: pittys17.gvo.it
-
- In article <4f2ftf$rjb@sparcserver.lrz-muenchen.de>,
- ua302aa@sun2.lrz-muenchen.de (Kurt Watzka) wrote:
-
- >>I have an array, part of a structure (i.e. msg.from="Myname"); since array is
- >>of defined length in the structure ( char from[36] ), I'd need to let msg.from
- >>36 chars length, padding it with spaces.
- >Why do you think so? As long as "msg.from" indeed _is_ a string, i.e. if
- >it is '\0'-terminated, there is no need to pad it with spaces. If you
-
- I don't need actually: the problem was that the array was part of a structure,
- and I wrote the entire structure binarily onto a file. As long as I was told
- the right way to do that is NOT to write the entire structure in one, but the
- different members one by one, my problem was solved.
- The structure, for instance, is a Fidonet packet.
-
- >>sizeof(structname), while char arrays are shorter than the ones defined in
- >>struct, I find additional garbage chars in the file, who fill the array
- >sizes.
- >So what? You want to write the whole structure, you write it. Those
- >"additional garbare chars" are in the struct, and they appear in the
- >file. If you want to avoid storing "garbage" chars, you cannot use
- >arrays of characters with a fixed size.
-
- That's the problem: avoid garbages and do use fixed-length arrays. The solution
- is to write each member one by one, or pad the string.. but the former method
- is used in a couple of sources I saw, so I use it myself ;).
-
- --
- Bye, AL!
-
- E-mail : albe@pinerolo.gvo.it
- Team OS/2 ITA Fidonet: 2:334/708 2:334/708.1
- OS2net : 81:439/63 81:439/63.1
-
- ***********************************************
- Pinerolo Internetworking BBS +39-121-393945
- Telnet bbs.piw.gvo.it
- ***********************************************
-